//
//  LARegistViewController.m
//  FMDB_Demo_Login
//
//  Created by libertyair on 15/5/28.
//  Copyright (c) 2015年 libertyair. All rights reserved.
//

#import "LARegistViewController.h"
#import "User.h"
#import "IDTools.h"

@interface LARegistViewController ()

@property (nonatomic,retain) User *user;
@property (weak, nonatomic) IBOutlet UITextField *userName;
@property (weak, nonatomic) IBOutlet UITextField *password;
@property (weak, nonatomic) IBOutlet UITextField *passwordAgain;

@end

@implementation LARegistViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setNavigation];
}

- (void)setNavigation //设置导航栏
{
//    self.navigationController.navigationBar.translucent = NO;
//    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:19/255.0 green:125/255.0 blue:236/255.0 alpha:1];
//    
    UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(backClick)];
    self.navigationItem.leftBarButtonItem = left;
}

#pragma mark - 点击返回
- (void)backClick
{
    [self.navigationController dismissViewControllerAnimated:YES completion:^{
        ;
    }];
}

- (IBAction)registClick:(id)sender   //点击注册按钮
{
    if ([self.userName.text isEqualToString: @""] || [self.password.text isEqualToString: @""] || [self.passwordAgain.text isEqualToString: @""])
        LALog(@"用户名或密码不能为空!");
    
    else if (![self.passwordAgain.text isEqualToString:self.password.text])
        LALog(@"密码不一致");
    
    else
    {
        LALog(@"yes");
        self.user = [User UserWithUserName:self.userName.text andPassword:self.password.text];
        if([IDTools addID:self.user])
            LALog(@"create new id successed");
        else
            LALog(@"create new id faild");
        [self dismissViewControllerAnimated:YES completion:^{
            ;
        }];
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

@end
